package jvm;

import lombok.SneakyThrows;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test3 {

    private Lock lock=new ReentrantLock();
    private Condition c1=lock.newCondition();
    private Condition c2=lock.newCondition();

    @SneakyThrows
    private void op1() {
        System.out.println("op1开始启动");
        lock.lock();
        c1.await();
        lock.unlock();
        System.out.println("op1终点");
    }

    @SneakyThrows
    private void op2() {
        System.out.println("op2开始启动");
        lock.lock();
        c2.await();
        lock.unlock();
        System.out.println("op2终点");
    }


    @SneakyThrows
    public static void main(String[] args) {

        Test3 test3=new Test3();

        new Thread(()->{
            test3.op1();
        }).start();

        new Thread(()->{
            test3.op2();
        }).start();

        Thread.sleep(1000);

        test3.lock.lock();
        test3.c1.signal();
        test3.c2.signal();
        test3.lock.unlock();

    }

}
